﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using ToolsetL.WeighingInstruments;

namespace ConsoleApp2
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //List<string> list = new List<string>() { "11111111" };

            //var data = list.Where(x=>x.Length>1).AsQueryable().Where(x => x.Length > 5);

            //Console.WriteLine(data.ElementType);

            //var obj = data.Provider.Execute<IEnumerable<string>>(data.Expression);

            ////Class<string> @class = new Class<string>()
            ////{

            ////    "1","1"
            ////}; 

            ////foreach (var arg in args) 
            ////{ 


            ////}
            ///
            //List<string> list = new List<string>() { "11111111" };
            //var data = list.Where(x=>x.Length>1).Where(x => x.Length > 5).ToList();

            //decimal d = 3.14159M;

            //Console.WriteLine(d.ToString("0.000"));

            //WeighingInstruments1 weighingInstruments = new WeighingInstruments1(new ToolsetL.Modle.SerialPortConfiguration() { COM = "COM11",BaudRate = 9600,Parity = System.IO.Ports.Parity.None,Databits = 8,Stopbits = System.IO.Ports.StopBits.One },20,10);
            //weighingInstruments.Open();

            //Task.Run(async () => { await Task.Delay(5000).ConfigureAwait(false); weighingInstruments.Close(); });

            //var result = weighingInstruments.GetStableWeightAsync(10).GetAwaiter().GetResult();

            //weighingInstruments.Dispose();  

            //Console.WriteLine(result);


            using (var w = new WeighingInstruments(new ToolsetL.Modle.SerialPortConfiguration()
            {
                COM = "COM11",
                Parity = System.IO.Ports.Parity.None,
                BaudRate = 9600,
                Databits = 8,
                Stopbits = System.IO.Ports.StopBits.One,
            }, 150, 100))
            {
                try
                {
                    w.Open();
                    Task.Run(() => { Thread.Sleep(5000);w.Dispose(); });
                    var result = w.GetStableWeightAsync(20).GetAwaiter().GetResult();
                    Console.WriteLine(result);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            Console.ReadLine();
        }
    }

    //public class Class<T> : IQueryable<T>
    //{
    //    public Expression Expression => throw new NotImplementedException();

    //    public Type ElementType => throw new NotImplementedException();

    //    public IQueryProvider Provider => throw new NotImplementedException();

    //    //public object Current => throw new NotImplementedException();

    //    //Class IEnumerator<Class>.Current => this;

    //    //public void Dispose()
    //    //{
    //    //    throw new NotImplementedException();
    //    //}

    //    //public IEnumerator<Class> GetEnumerator()
    //    //{
    //    //    return new IEnumerator<Class>() { };    
    //    //}

    //    //public bool MoveNext()
    //    //{
    //    //    return true;    
    //    //}

    //    //public void Reset()
    //    //{
    //    //    throw new NotImplementedException();
    //    //}

    //    //IEnumerator IEnumerable.GetEnumerator()
    //    //{
    //    //    return (new string[] { "1" }).GetEnumerator();
     

    //    public void Add(T item) 
        
    //    { }

    //    public IEnumerator<T> GetEnumerator()
    //    {
    //        throw new NotImplementedException();
    //    }

    //    IEnumerator IEnumerable.GetEnumerator()
    //    {
    //        throw new NotImplementedException();
    //    }
    //}
}
